{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>样地号</th>\n",
       "      <th>样地类别</th>\n",
       "      <th>纵坐标</th>\n",
       "      <th>横坐标</th>\n",
       "      <th>GPS纵坐标</th>\n",
       "      <th>GPS横坐标</th>\n",
       "      <th>县代码</th>\n",
       "      <th>地貌</th>\n",
       "      <th>海拔</th>\n",
       "      <th>坡向</th>\n",
       "      <th>...</th>\n",
       "      <th>活立蓄积</th>\n",
       "      <th>林木蓄积</th>\n",
       "      <th>散生蓄积</th>\n",
       "      <th>四旁蓄积</th>\n",
       "      <th>枯损蓄积</th>\n",
       "      <th>采伐蓄积</th>\n",
       "      <th>x</th>\n",
       "      <th>y</th>\n",
       "      <th>Unnamed: 76</th>\n",
       "      <th>Unnamed: 77</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>11</td>\n",
       "      <td>3680</td>\n",
       "      <td>19364</td>\n",
       "      <td>3679845</td>\n",
       "      <td>19364015</td>\n",
       "      <td>322</td>\n",
       "      <td>3</td>\n",
       "      <td>1620</td>\n",
       "      <td>1</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>3680000</td>\n",
       "      <td>19364000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>11</td>\n",
       "      <td>3680</td>\n",
       "      <td>19372</td>\n",
       "      <td>3680005</td>\n",
       "      <td>19371995</td>\n",
       "      <td>322</td>\n",
       "      <td>3</td>\n",
       "      <td>1500</td>\n",
       "      <td>5</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>3680000</td>\n",
       "      <td>19372000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>11</td>\n",
       "      <td>3680</td>\n",
       "      <td>19376</td>\n",
       "      <td>3679985</td>\n",
       "      <td>19376010</td>\n",
       "      <td>322</td>\n",
       "      <td>3</td>\n",
       "      <td>1100</td>\n",
       "      <td>4</td>\n",
       "      <td>...</td>\n",
       "      <td>0.764</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.764</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.225</td>\n",
       "      <td>3680000</td>\n",
       "      <td>19376000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>11</td>\n",
       "      <td>3680</td>\n",
       "      <td>19380</td>\n",
       "      <td>3680005</td>\n",
       "      <td>19379995</td>\n",
       "      <td>322</td>\n",
       "      <td>3</td>\n",
       "      <td>1680</td>\n",
       "      <td>7</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>3680000</td>\n",
       "      <td>19380000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>11</td>\n",
       "      <td>3680</td>\n",
       "      <td>19392</td>\n",
       "      <td>3680000</td>\n",
       "      <td>19391985</td>\n",
       "      <td>322</td>\n",
       "      <td>3</td>\n",
       "      <td>1370</td>\n",
       "      <td>5</td>\n",
       "      <td>...</td>\n",
       "      <td>0.846</td>\n",
       "      <td>0.846</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.230</td>\n",
       "      <td>3680000</td>\n",
       "      <td>19392000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5815</th>\n",
       "      <td>11956</td>\n",
       "      <td>11</td>\n",
       "      <td>3272</td>\n",
       "      <td>19712</td>\n",
       "      <td>3272000</td>\n",
       "      <td>19712000</td>\n",
       "      <td>1023</td>\n",
       "      <td>6</td>\n",
       "      <td>30</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>0.859</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.859</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.006</td>\n",
       "      <td>3272000</td>\n",
       "      <td>19712000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5816</th>\n",
       "      <td>11965</td>\n",
       "      <td>11</td>\n",
       "      <td>3264</td>\n",
       "      <td>19688</td>\n",
       "      <td>3264000</td>\n",
       "      <td>19688000</td>\n",
       "      <td>1023</td>\n",
       "      <td>6</td>\n",
       "      <td>20</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>3264000</td>\n",
       "      <td>19688000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5817</th>\n",
       "      <td>11966</td>\n",
       "      <td>11</td>\n",
       "      <td>3264</td>\n",
       "      <td>19700</td>\n",
       "      <td>3264000</td>\n",
       "      <td>19700000</td>\n",
       "      <td>1023</td>\n",
       "      <td>6</td>\n",
       "      <td>20</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>3264000</td>\n",
       "      <td>19700000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5818</th>\n",
       "      <td>11967</td>\n",
       "      <td>11</td>\n",
       "      <td>3264</td>\n",
       "      <td>19704</td>\n",
       "      <td>3264000</td>\n",
       "      <td>19704000</td>\n",
       "      <td>1023</td>\n",
       "      <td>6</td>\n",
       "      <td>30</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>3264000</td>\n",
       "      <td>19704000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5819</th>\n",
       "      <td>11968</td>\n",
       "      <td>11</td>\n",
       "      <td>3264</td>\n",
       "      <td>19708</td>\n",
       "      <td>3264000</td>\n",
       "      <td>19708000</td>\n",
       "      <td>1023</td>\n",
       "      <td>6</td>\n",
       "      <td>30</td>\n",
       "      <td>9</td>\n",
       "      <td>...</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.000</td>\n",
       "      <td>3264000</td>\n",
       "      <td>19708000</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5820 rows × 78 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "        样地号  样地类别   纵坐标    横坐标   GPS纵坐标    GPS横坐标   县代码  地貌    海拔  坡向  ...  \\\n",
       "0         1    11  3680  19364  3679845  19364015   322   3  1620   1  ...   \n",
       "1         2    11  3680  19372  3680005  19371995   322   3  1500   5  ...   \n",
       "2         3    11  3680  19376  3679985  19376010   322   3  1100   4  ...   \n",
       "3         4    11  3680  19380  3680005  19379995   322   3  1680   7  ...   \n",
       "4         5    11  3680  19392  3680000  19391985   322   3  1370   5  ...   \n",
       "...     ...   ...   ...    ...      ...       ...   ...  ..   ...  ..  ...   \n",
       "5815  11956    11  3272  19712  3272000  19712000  1023   6    30   9  ...   \n",
       "5816  11965    11  3264  19688  3264000  19688000  1023   6    20   9  ...   \n",
       "5817  11966    11  3264  19700  3264000  19700000  1023   6    20   9  ...   \n",
       "5818  11967    11  3264  19704  3264000  19704000  1023   6    30   9  ...   \n",
       "5819  11968    11  3264  19708  3264000  19708000  1023   6    30   9  ...   \n",
       "\n",
       "       活立蓄积   林木蓄积  散生蓄积   四旁蓄积  枯损蓄积   采伐蓄积        x         y  Unnamed: 76  \\\n",
       "0     0.000  0.000   0.0  0.000   0.0  0.000  3680000  19364000          NaN   \n",
       "1     0.000  0.000   0.0  0.000   0.0  0.000  3680000  19372000          NaN   \n",
       "2     0.764  0.000   0.0  0.764   0.0  0.225  3680000  19376000          NaN   \n",
       "3     0.000  0.000   0.0  0.000   0.0  0.000  3680000  19380000          NaN   \n",
       "4     0.846  0.846   0.0  0.000   0.0  0.230  3680000  19392000          NaN   \n",
       "...     ...    ...   ...    ...   ...    ...      ...       ...          ...   \n",
       "5815  0.859  0.000   0.0  0.859   0.0  0.006  3272000  19712000          NaN   \n",
       "5816  0.000  0.000   0.0  0.000   0.0  0.000  3264000  19688000          NaN   \n",
       "5817  0.000  0.000   0.0  0.000   0.0  0.000  3264000  19700000          NaN   \n",
       "5818  0.000  0.000   0.0  0.000   0.0  0.000  3264000  19704000          NaN   \n",
       "5819  0.000  0.000   0.0  0.000   0.0  0.000  3264000  19708000          NaN   \n",
       "\n",
       "      Unnamed: 77  \n",
       "0             NaN  \n",
       "1             NaN  \n",
       "2             NaN  \n",
       "3             NaN  \n",
       "4             NaN  \n",
       "...           ...  \n",
       "5815          NaN  \n",
       "5816          NaN  \n",
       "5817          NaN  \n",
       "5818          NaN  \n",
       "5819          NaN  \n",
       "\n",
       "[5820 rows x 78 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv(r'./使用数据\\一清数据.csv',encoding='gb2312')\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "df=df[df['地类'].isin(['111','131','132'])]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([131, 111, 132], dtype=int64)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['地类'].unique()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "面积估计"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "groupby_df = df.groupby('地类')['样地号'].agg([np.size])\n",
    "groupby_df['面积成数估计值'] = groupby_df['size'].apply(lambda x:x/np.sum(groupby_df['size']))\n",
    "groupby_df['面积成数估计值标准差'] = groupby_df['面积成数估计值'].apply(lambda x:np.sqrt(x*(1-x)/(np.sum(groupby_df['size'])-7)))\n",
    "groupby_df['面积成数估计值标准误'] = groupby_df.apply(lambda x:x['面积成数估计值标准差']/np.sqrt(x['size']),axis=1)\n",
    "groupby_df['面积估计值'] = groupby_df['面积成数估计值'].apply(lambda x:x*667*np.sum(groupby_df['size']))\n",
    "groupby_df['面积估计值误差限'] = groupby_df['面积成数估计值标准差'].apply(lambda x:x*2)\n",
    "groupby_df['抽样精度'] = groupby_df.apply(lambda x:1-2*x['面积成数估计值标准误']/x['面积成数估计值'],axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>size</th>\n",
       "      <th>面积成数估计值</th>\n",
       "      <th>面积成数估计值标准差</th>\n",
       "      <th>面积成数估计值标准误</th>\n",
       "      <th>面积估计值</th>\n",
       "      <th>面积估计值误差限</th>\n",
       "      <th>抽样精度</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>地类</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>1897</td>\n",
       "      <td>0.788773</td>\n",
       "      <td>0.008335</td>\n",
       "      <td>0.000191</td>\n",
       "      <td>1265299.0</td>\n",
       "      <td>0.016671</td>\n",
       "      <td>0.999515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>349</td>\n",
       "      <td>0.145114</td>\n",
       "      <td>0.007193</td>\n",
       "      <td>0.000385</td>\n",
       "      <td>232783.0</td>\n",
       "      <td>0.014385</td>\n",
       "      <td>0.994694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>159</td>\n",
       "      <td>0.066112</td>\n",
       "      <td>0.005074</td>\n",
       "      <td>0.000402</td>\n",
       "      <td>106053.0</td>\n",
       "      <td>0.010148</td>\n",
       "      <td>0.987827</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     size   面积成数估计值  面积成数估计值标准差  面积成数估计值标准误      面积估计值  面积估计值误差限      抽样精度\n",
       "地类                                                                        \n",
       "111  1897  0.788773    0.008335    0.000191  1265299.0  0.016671  0.999515\n",
       "131   349  0.145114    0.007193    0.000385   232783.0  0.014385  0.994694\n",
       "132   159  0.066112    0.005074    0.000402   106053.0  0.010148  0.987827"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groupby_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>size</th>\n",
       "      <th>面积成数估计值</th>\n",
       "      <th>面积成数估计值标准差</th>\n",
       "      <th>面积成数估计值标准误</th>\n",
       "      <th>面积估计值</th>\n",
       "      <th>面积估计值误差限</th>\n",
       "      <th>抽样精度</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>地类</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>1897</td>\n",
       "      <td>0.788773</td>\n",
       "      <td>0.008335</td>\n",
       "      <td>0.000191</td>\n",
       "      <td>1265299.0</td>\n",
       "      <td>0.016671</td>\n",
       "      <td>0.999515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>349</td>\n",
       "      <td>0.145114</td>\n",
       "      <td>0.007193</td>\n",
       "      <td>0.000385</td>\n",
       "      <td>232783.0</td>\n",
       "      <td>0.014385</td>\n",
       "      <td>0.994694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>159</td>\n",
       "      <td>0.066112</td>\n",
       "      <td>0.005074</td>\n",
       "      <td>0.000402</td>\n",
       "      <td>106053.0</td>\n",
       "      <td>0.010148</td>\n",
       "      <td>0.987827</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     size   面积成数估计值  面积成数估计值标准差  面积成数估计值标准误      面积估计值  面积估计值误差限      抽样精度\n",
       "地类                                                                        \n",
       "111  1897  0.788773    0.008335    0.000191  1265299.0  0.016671  0.999515\n",
       "131   349  0.145114    0.007193    0.000385   232783.0  0.014385  0.994694\n",
       "132   159  0.066112    0.005074    0.000402   106053.0  0.010148  0.987827"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groupby_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>样地数目</th>\n",
       "      <th>面积成数估计值</th>\n",
       "      <th>面积成数估计值标准差</th>\n",
       "      <th>面积成数估计值标准误</th>\n",
       "      <th>面积估计值</th>\n",
       "      <th>面积估计值误差限</th>\n",
       "      <th>抽样精度</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>地类</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>1897</td>\n",
       "      <td>0.788773</td>\n",
       "      <td>0.008335</td>\n",
       "      <td>0.000191</td>\n",
       "      <td>1265299.0</td>\n",
       "      <td>0.016671</td>\n",
       "      <td>0.999515</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>349</td>\n",
       "      <td>0.145114</td>\n",
       "      <td>0.007193</td>\n",
       "      <td>0.000385</td>\n",
       "      <td>232783.0</td>\n",
       "      <td>0.014385</td>\n",
       "      <td>0.994694</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>159</td>\n",
       "      <td>0.066112</td>\n",
       "      <td>0.005074</td>\n",
       "      <td>0.000402</td>\n",
       "      <td>106053.0</td>\n",
       "      <td>0.010148</td>\n",
       "      <td>0.987827</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "     样地数目   面积成数估计值  面积成数估计值标准差  面积成数估计值标准误      面积估计值  面积估计值误差限      抽样精度\n",
       "地类                                                                        \n",
       "111  1897  0.788773    0.008335    0.000191  1265299.0  0.016671  0.999515\n",
       "131   349  0.145114    0.007193    0.000385   232783.0  0.014385  0.994694\n",
       "132   159  0.066112    0.005074    0.000402   106053.0  0.010148  0.987827"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "groupby_df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "groupby_df.to_excel(r'./输出数据/面积估计.xlsx')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "蓄积估计"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [],
   "source": [
    "grouped_df1 = df.groupby('地类')['活立蓄积'].agg([np.size,np.mean,np.var,np.std])\n",
    "grouped_df1['面积成数估计值标准误'] = grouped_df1.apply(lambda x:x['std']/np.sqrt(x['size']),axis=1)\n",
    "grouped_df1['总体总量估计值'] = grouped_df1.apply(lambda x:x['size']*x['mean'],axis=1)\n",
    "grouped_df1['总体总量估计值误差限'] = grouped_df1.apply(lambda x:x['size']*x['面积成数估计值标准误']*2,axis=1)\n",
    "grouped_df1['抽样精度'] = grouped_df1.apply(lambda x:1-(2*x['面积成数估计值标准误']/x['mean']),axis=1)\n",
    "grouped_df1 = grouped_df1.rename(columns={'mean':'样本平均数','size':'样地数目','var':'样地方差','std':'样地标准差'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>样地数目</th>\n",
       "      <th>样本平均数</th>\n",
       "      <th>样地方差</th>\n",
       "      <th>样地标准差</th>\n",
       "      <th>面积成数估计值标准误</th>\n",
       "      <th>总体总量估计值</th>\n",
       "      <th>总体总量估计值误差限</th>\n",
       "      <th>抽样精度</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>地类</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>1897.0</td>\n",
       "      <td>3.978224</td>\n",
       "      <td>12.231025</td>\n",
       "      <td>3.497288</td>\n",
       "      <td>0.080297</td>\n",
       "      <td>7546.691</td>\n",
       "      <td>304.645731</td>\n",
       "      <td>0.959632</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>349.0</td>\n",
       "      <td>0.124023</td>\n",
       "      <td>0.083276</td>\n",
       "      <td>0.288576</td>\n",
       "      <td>0.015447</td>\n",
       "      <td>43.284</td>\n",
       "      <td>10.782077</td>\n",
       "      <td>0.750899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>159.0</td>\n",
       "      <td>0.112239</td>\n",
       "      <td>0.066385</td>\n",
       "      <td>0.257653</td>\n",
       "      <td>0.020433</td>\n",
       "      <td>17.846</td>\n",
       "      <td>6.497770</td>\n",
       "      <td>0.635898</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       样地数目     样本平均数       样地方差     样地标准差  面积成数估计值标准误   总体总量估计值  总体总量估计值误差限  \\\n",
       "地类                                                                             \n",
       "111  1897.0  3.978224  12.231025  3.497288    0.080297  7546.691  304.645731   \n",
       "131   349.0  0.124023   0.083276  0.288576    0.015447    43.284   10.782077   \n",
       "132   159.0  0.112239   0.066385  0.257653    0.020433    17.846    6.497770   \n",
       "\n",
       "         抽样精度  \n",
       "地类             \n",
       "111  0.959632  \n",
       "131  0.750899  \n",
       "132  0.635898  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grouped_df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>样地数目</th>\n",
       "      <th>样本平均数</th>\n",
       "      <th>样地方差</th>\n",
       "      <th>样地标准差</th>\n",
       "      <th>面积成数估计值标准误</th>\n",
       "      <th>总体总量估计值</th>\n",
       "      <th>总体总量估计值误差限</th>\n",
       "      <th>抽样精度</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>地类</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>111</th>\n",
       "      <td>1897.0</td>\n",
       "      <td>3.978224</td>\n",
       "      <td>12.231025</td>\n",
       "      <td>3.497288</td>\n",
       "      <td>0.080297</td>\n",
       "      <td>7546.691</td>\n",
       "      <td>304.645731</td>\n",
       "      <td>0.959632</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>131</th>\n",
       "      <td>349.0</td>\n",
       "      <td>0.124023</td>\n",
       "      <td>0.083276</td>\n",
       "      <td>0.288576</td>\n",
       "      <td>0.015447</td>\n",
       "      <td>43.284</td>\n",
       "      <td>10.782077</td>\n",
       "      <td>0.750899</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>132</th>\n",
       "      <td>159.0</td>\n",
       "      <td>0.112239</td>\n",
       "      <td>0.066385</td>\n",
       "      <td>0.257653</td>\n",
       "      <td>0.020433</td>\n",
       "      <td>17.846</td>\n",
       "      <td>6.497770</td>\n",
       "      <td>0.635898</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       样地数目     样本平均数       样地方差     样地标准差  面积成数估计值标准误   总体总量估计值  总体总量估计值误差限  \\\n",
       "地类                                                                             \n",
       "111  1897.0  3.978224  12.231025  3.497288    0.080297  7546.691  304.645731   \n",
       "131   349.0  0.124023   0.083276  0.288576    0.015447    43.284   10.782077   \n",
       "132   159.0  0.112239   0.066385  0.257653    0.020433    17.846    6.497770   \n",
       "\n",
       "         抽样精度  \n",
       "地类             \n",
       "111  0.959632  \n",
       "131  0.750899  \n",
       "132  0.635898  "
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "grouped_df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "groupby_df.to_excel(r'./输出数据/蓄积估计.xlsx')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
